﻿@{
    ViewBag.Title = "日报表填写出错维护";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            DisableBackspace();
            initListcombo();
            RevistMainGrid();
        });
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableFormDM", "#tbbb", "#DriverReportDM");
        });

        //#region 为Combobox增加--请选择--
        function EUIcombobox(jqS, o) {
            $.ajax({
                type: "POST",
                async: false,
                url: o.url,
                dataType: "JSON",
                success: function (data1, textStatus, jqXHR) {
                    o.data = o.OneOption.concat(data1);
                    delete o.url;
                    delete o.OneOption;
                    $(jqS).combobox(o);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("获取字典数据失败！可能是已经超时，请重新登录！");
                }
            });
        }
        function initListcombo() {

            EUIcombobox("#zcenterCode", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',

                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    EUIcombobox("#zstationCode", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',

                        editable: false,
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }]
                    });
                }
            });
            //#endregion

            //#region 出车分站
            EUIcombobox("#zstationCode", {
                url: '@Url.Content("~/Medical/GetStation?code=")',
                valueField: 'ID',
                textField: 'Name',

                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var zz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                    EUIcombobox("#zPlateNumber", {
                        url: zz,
                        valueField: 'AmbulanceCode',
                        textField: 'PlateNumber',
                        editable: false,
                        OneOption: [{
                            AmbulanceCode: "",
                            PlateNumber: ""
                        }]
                    });
                },
                onChange: function (newValue, oldValue) {

                    $("#zPlateNumber").combobox('clear');
                }
            });

            //车辆牌号 初始化
            EUIcombobox("#zPlateNumber", {
                url: '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")',
                valueField: 'AmbulanceCode',
                textField: 'PlateNumber',
                editable: true,
                OneOption: [{
                    AmbulanceCode: "",
                    PlateNumber: ""
                }]
            });
            $('#zReportDateStart').datebox({
                value: $.GetMonthFirstday(),
                required: true
            }); 

            $('#zReportDateEnd').datebox({
                value: $.GetToday(),
                required: true
            });
        }

        function dosearchclick() {
            $('#DriverReportDM').datagrid({
                pageNumber: 1,
                queryParams: {
                    zcenterCode: $('#zcenterCode').combobox('getValue'),
                    zstationCode: $('#zstationCode').combobox('getValue'),
                    zPlateNumber: $('#zPlateNumber').textbox('getText'),
                    zReportDateStart: $('#zReportDateStart').datebox('getValue'),
                    zReportDateEnd: $('#zReportDateEnd').datebox('getValue'),
                    zAgentWorkID: $('#zAgentWorkID').textbox('getValue'),
                    zMoreKM: $('#zMoreKM').numberbox('getValue')

                }
            });

        }
        function RevistMainGrid() {
            $('#DriverReportDM').datagrid({
                width: 'auto',
                height: 'auto',
                // fitColumns: true, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DM/DriverReportDM/GetReportMainDM")',
                striped: true,
                singleSelect: true,
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5
                pageList: [10, 15, 20],//设置 页容量下拉框

                queryParams: {
                    zcenterCode: $('#zcenterCode').combobox('getValue'),
                    zstationCode: $('#zstationCode').combobox('getValue'),
                    zPlateNumber: $('#zPlateNumber').textbox('getText'),
                    zReportDateStart: $('#zReportDateStart').datebox('getValue'),
                    zReportDateEnd: $('#zReportDateEnd').datebox('getValue'),
                    zAgentWorkID: $('#zAgentWorkID').textbox('getValue'),
                    zMoreKM: $('#zMoreKM').numberbox('getValue')

                },
                frozenColumns: [[
                    { field: "ID", hidden: true },
                    { field: "CenterCode", hidden: true },
                    { field: "StationCode", hidden: true },
                     { field: "StationName", title: "分站", width: '8%', align: "center" },
                      { field: "FillState", title: "日报状态", width: '12%', align: "center" },
                    { field: "AgentWorkID", title: "填写人工号", width: '6%', align: "center" },
                        { field: "AmbulanceNumber", title: "车辆", width: '7%', align: "center" },
                    { field: "ReportDate", title: "日报日期", width: '8%', align: "center", formatter: $.formatDate },
                    { field: "BanCi", title: "班次", width: '8%', align: "center" },
                     { field: "DriverName", title: "司机", width: '8%', align: "center" },
        { field: "OffDutyKM", title: "下班路码", width: '7%', align: "center" },
         { field: "OnDutyKM", title: "上班路码", width: '7%', align: "center" },
          { field: "DayKM", title: "公里数", width: '6%', align: "center", formatter: formatDateI},
                { field: "TaskTimes", title: "车次", width: '4%', align: "center" },
        { field: "LastModifyTime", title: "最后填写时间", width: '13%', align: "center", formatter: $.formatTime },
        { field: "LastModifier", title: "最后填写人", width: '7%', align: "center" }
                ]],
                toolbar: [
                  {
                      id: 'btnAdd',
                      text: '修改',
                      iconCls: 'icon-add',
                      handler: function () {
                          var r = $('#DriverReportDM').datagrid('getSelected');
                          if (r) {
                          
                              $('#DMDialog').dialog('open');

                              $('#txtOffDutyKM').numberbox('setValue', r.OffDutyKM);
                              $('#txtOnDutyKM').numberbox('setValue', r.OnDutyKM);
                              $('#txtDayKM').numberbox('setValue', r.DayKM);


                              //$('#DriverReportDM').datagrid('')
                              // EditRowDate = "";
                              //initPickTaskGrid();
                          }
                          else { $.messager.alert('提示信息', '请选择数据行！') }
                      }
                  }
                ],

                onLoadSuccess: function (data) {

                }
            });
            $.setGridWithSearchBar("#TableFormDM", "#tbbb", "#DriverReportDM");
        }

        function formatDateI(val, row) {
         
            if (val >= 500) {  //保险小于1个月提醒
                return '<span style="background-color:#ffee00;color:red;">' + val + '</span>';
            } else {
                return val;
            }
        }


        function submitSaveDM() {
            var r = $('#DriverReportDM').datagrid('getSelected');
            var sbOffDutyKM  =  $('#txtOffDutyKM').numberbox('getValue');
            var sbOnDutyKM = $('#txtOnDutyKM').numberbox('getValue');
            var sbDayKM = $('#txtDayKM').numberbox('getValue');
            var sbID = r.ID;
         
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DM/DriverReportDM/SaveDriverReportDM")',
                data:
                    {
                        sbOffDutyKM: sbOffDutyKM,
                        sbOnDutyKM: sbOnDutyKM,
                        sbDayKM: sbDayKM,
                        sbID: sbID
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                        // Materials.length = 0;
                        $('#DMDialog').dialog('close');

                        dosearchclick();
                       
                    });
                }
            });
        }


    </script>
}
<div id="TableFormDM" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'日报表填写出错维护',iconCls:'icon-custom-cPrice'">
        <div id="tbbb" data-options="region:'north'" style="overflow: hidden; padding: 10px">
            <table border="0">
                <tr>
                    <td>分中心：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 120px" id="zcenterCode">
                    </td>
                    <td>分站：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 120px" id="zstationCode">
                    </td>
                    <td>车牌号码：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 120px" id="zPlateNumber">
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    </tr>
                <tr>
                    <td>
                        日报日期：
                    </td>
                    <td>
                        <input class="easyui-datebox" style="width: 120px" id="zReportDateStart">

                    </td>
                    <td>
                        至：
                    </td>
                    <td>
                        <input class="easyui-datebox" style="width: 120px" id="zReportDateEnd">
                    </td>
                    <td>填写人工号：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-textbox" style="width: 120px" id="zAgentWorkID">
                    </td>
                    <td>公里数大于：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-numberbox" style="width: 100px" id="zMoreKM">
                    </td>
                    <td>
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="dosearchclick();">查询</a>
                    </td>
                </tr>

            </table>

        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="DriverReportDM" border="0"></table>
        </div>
    </div>
</div>
<div id="DMDialog" class="easyui-dialog" title="请修改正确的路码信息" data-options="modal:true,
     collapsible:false,
     minimizable:false,
     maximizable:true,
     closed:true,
     resizable:true,
     iconCls:'icon-custom-cDelivery'
     " style="width: 300px; height: 220px; padding: 0px; ">
   
    <div id="tbbdialog" style="padding: 5px; height: auto">
        <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
            <tr style="height:35px;">
                <td align="right" valign="middle" >下班路码：</td>
                <td align="left" valign="middle">
                    <input class="easyui-numberbox" style="width:120px" id="txtOffDutyKM" >
                </td>
                </tr>
            <tr style="height:35px;">
                <td align="right" valign="middle">上班路码：</td>
                <td align="left" valign="middle">
                    <input class="easyui-numberbox" style="width: 120px" id="txtOnDutyKM" >
                </td>
            </tr>
            <tr style="height:35px;">
                <td align="right" valign="middle">公里数：</td>
                <td align="left" valign="middle">
                    <input class="easyui-numberbox" style="width: 120px" id="txtDayKM">
                </td>
            </tr>
            <tr style="height:35px;">
                <td colspan="2" align="center">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnSaveDM" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="submitSaveDM();">点击保存</a>
                </td>

            </tr>
        </table>

    </div>
    
</div>


